jun.BiayaSalesLainGrid = Ext.extend(Ext.grid.GridPanel, {
    title: "BiayaSalesLain",
    id: 'docs-jun.BiayaSalesLainGrid',
    iconCls: "silk-grid",
    viewConfig: {
        forceFit: true
    },
    sm: new Ext.grid.RowSelectionModel({singleSelect: true}),
    columns: [
        {
            header: 'Keterangan',
            resizable: true,
            dataIndex: 'nama_biaya',
            width: 100
        },
        {
            header: 'Jumlah',
            resizable: true,
            dataIndex: 'amount',
            width: 100,
            align: "right",
            renderer: Ext.util.Format.numberRenderer("0,0")
        },
        {
            header: 'Kode Rekening',
            resizable: true,
            dataIndex: 'account_code',
            width: 100
        },
        {
            header: 'Nama Rekening',
            resizable: true,
            dataIndex: 'account_code',
            width: 100,
            renderer: jun.renderNamaChart
        }
    ],
    initComponent: function () {
        this.store = jun.rztBiayaSalesLain;
        this.tbar = {
            xtype: 'toolbar',
            items: [
                {
                    xtype: 'label',
                    text: '\xA0Keterangan :\xA0'
                },
                {
                    xtype: 'uctextfield',
                    ref: '../nama',
                    maxLength: 50,
//                    allowBlank: false,
                    width: 100
                },
                {
                    xtype: 'label',
                    text: '\xA0\xA0Kode :\xA0'
                },
                {
                    xtype: 'combo',
                    typeAhead: true,
                    triggerAction: 'all',
                    lazyRender: true,
                    mode: 'local',
                    fieldLabel: 'Kode Rekening',
                    store: jun.rztChartMasterNonKasBank,
                    forceSelection: true,
                    valueField: 'account_code',
                    matchFieldWidth: !1,
                    itemSelector: "div.search-item",
                    tpl: new Ext.XTemplate('<tpl for="."><div class="search-item">', '<h3><span">{account_code} - {account_name}</span></h3><br />{description}', "</div></tpl>"),
                    listWidth: 300, editable: !0,
                    displayField: 'account_name',
                    ref: '../kode',
//                    allowBlank: false,
                    width: 100
                },
                {
                    xtype: 'label',
                    text: '\xA0\xA0Jumlah :\xA0'
                },
                {
                    xtype: 'numericfield',
                    ref: '../jml',
                    maxLength: 30,
                    value:0,
                    width: 100
                },
                {
                    xtype: 'tbseparator'
                },
                {
                    xtype: 'button',
                    text: 'Add',
                    ref: '../btnAdd'
                },
                {
                    xtype: 'tbseparator'
                },
                {
                    xtype: 'button',
                    text: 'Del',
                    ref: '../btnDelete'
                }
            ]
        };
        jun.BiayaSalesLainGrid.superclass.initComponent.call(this);
        this.btnAdd.on('Click', this.loadForm, this);
        this.btnDelete.on('Click', this.deleteRec, this);
        this.getSelectionModel().on('rowselect', this.getrow, this);
    },
    getrow: function (sm, idx, r) {
        this.record = r;
        var selectedz = this.sm.getSelections();
    },
    loadForm: function () {
        var nama = this.nama.getValue();
        var kode = this.kode.getValue();
        if(nama == "" || kode == ""){
            Ext.MessageBox.alert("Error", "Keterangan atau Kode tidak boleh kosong.");
            return;
        }
//        var a = jun.rztBiayaSalesLain.findExact("nama_biaya", nama);
//        if (a > -1) {
//            Ext.MessageBox.alert("Error", "Biaya sudah dimansukkan.");
//            return;
//        }
//
//        var a = jun.rztBiayaSalesLain.findExact("account_code", kode);
//        if (a > -1) {
//            Ext.MessageBox.alert("Error", "Kode sudah dimansukkan.");
//            return;
//        }
        var jml = parseFloat(this.jml.getValue());
        if(jml <= 0){
            Ext.MessageBox.alert("Error", "Jumlah harus lebih dari nol.");
            return;
        }
        var c = jun.rztBiayaSalesLain.recordType,
            d = new c({
                nama_biaya: nama,
                account_code: kode,
                amount: jml
            });
        jun.rztBiayaSalesLain.add(d);
        this.store.refreshData();
        this.nama.reset();
        this.jml.reset();
        this.kode.reset();
    },
    loadEditForm: function () {
        var selectedz = this.sm.getSelected();
        //var dodol = this.store.getAt(0);
        if (selectedz == "") {
            Ext.MessageBox.alert("Warning", "Anda belum memilih Jenis Pelayanan");
            return;
        }
        var idz = selectedz.json.biaya_sales_lain_id;
        var form = new jun.BiayaSalesLainWin({modez: 1, id: idz});
        form.show(this);
        form.formz.getForm().loadRecord(this.record);
    },
    deleteRec: function () {
        Ext.MessageBox.confirm('Pertanyaan', 'Apakah anda yakin ingin menghapus data ini?', this.deleteRecYes, this);
    },
    deleteRecYes: function (btn) {
        if (btn == 'no') {
            return;
        }
        var record = this.sm.getSelected();
        // Check is list selected
        if (record == "") {
            Ext.MessageBox.alert("Warning", "Anda Belum Memilih Data");
            return;
        }
        this.store.remove(record), this.store.refreshData();
    }
})
